<!--
 * @Author: your name
 * @Date: 2021-11-12 11:17:42
 * @LastEditTime: 2021-11-12 11:48:27
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \vue-note\day02\05.v-for的基本使用.html
-->
<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>05.v-for的基本使用</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.14/vue.js"></script>
  </head>
  <body>
    <div id="app">
      <ul>
        <li v-for="(item,index) in list" :key="item.id">{{item.name}}</li>
      </ul>
      <button @click="add">添加</button>
      <hr />
    </div>
    <script>
      new Vue({
        el: "#app",
        data: {
          msg: "hello",
          list: [
            { id: 1, name: "jack", age: 1 },
            { id: 2, name: "rose", age: 18 },
            { id: 3, name: "jerry", age: 20 },
          ],
        },
        methods: {
          add() {
            this.list.unshift({
              id: 4,
              name: "hangman",
              age: 22,
            });
          },
        },
      });
      /**
       * 使用v-for来遍历数据时，最好是加上key
       */
    </script>
  </body>
</html>
